package com.material.web.controller.supplier;

import com.material.common.annotation.Log;
import com.material.common.core.controller.BaseController;
import com.material.common.core.domain.entity.SysUser;
import com.material.common.core.page.TableDataInfo;
import com.material.common.enums.BusinessType;
import com.material.common.utils.SecurityUtils;
import com.material.common.utils.poi.ExcelUtil;
import com.material.pound.FuelPoundParams;
import com.material.pound.domain.FuelPound;
import com.material.pound.service.IFuelPoundService;
import com.material.pound.vo.FuelDiaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author ganxinge
 */
@RestController
@RequestMapping("/supplier/diary")
public class SupplierDiaryController extends BaseController {

    @Autowired
    private IFuelPoundService fuelPoundService;

    @PreAuthorize("@ss.hasPermi('pound:pound:list')")
    @GetMapping("/listByReservationDate")
    public TableDataInfo listByReservationDate(FuelPoundParams fuelPoundParams){
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        startPage();
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundByReservationDate(fuelPoundParams);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('pound:pound:list')")
    @GetMapping("/listByFuelId")
    public TableDataInfo listByFuelId(FuelPoundParams fuelPoundParams){
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        startPage();
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundByFuelId(fuelPoundParams);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('pound:pound:list')")
    @GetMapping("/listByCarNum")
    public TableDataInfo listByCarNum(FuelPoundParams fuelPoundParams){
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        startPage();
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundByCarNum(fuelPoundParams);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('pound:pound:list')")
    @GetMapping("/listBySupplierId")
    public TableDataInfo listBySupplierId(FuelPoundParams fuelPoundParams){
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        startPage();
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundBySupplierId(fuelPoundParams);
        return getDataTable(list);
    }

    /**
     * 导出送料日报，按预约到达日期分组导出
     */
    @PreAuthorize("@ss.hasPermi('pound:pound:export')")
    @Log(title = "送料日报", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByReservationDate")
    public void exportByReservationDate(HttpServletResponse response, FuelPoundParams fuelPoundParams)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundByReservationDate(fuelPoundParams);
        ExcelUtil<FuelDiaryVo> util = new ExcelUtil<FuelDiaryVo>(FuelDiaryVo.class);
        util.exportExcel(response, list, "送料信息数据");
    }

    /**
     * 导出送料日报，按品名分组导出
     */
    @PreAuthorize("@ss.hasPermi('pound:pound:export')")
    @Log(title = "送料日报", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByFuel")
    public void exportByFuel(HttpServletResponse response, FuelPoundParams fuelPoundParams)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundByFuelId(fuelPoundParams);
        ExcelUtil<FuelDiaryVo> util = new ExcelUtil<FuelDiaryVo>(FuelDiaryVo.class);
        util.exportExcel(response, list, "送料信息数据");
    }

    /**
     * 导出送料日报，按车牌号分组导出
     */
    @PreAuthorize("@ss.hasPermi('pound:pound:export')")
    @Log(title = "送料日报", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByCar")
    public void exportByCar(HttpServletResponse response, FuelPoundParams fuelPoundParams)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundByCarNum(fuelPoundParams);
        ExcelUtil<FuelDiaryVo> util = new ExcelUtil<FuelDiaryVo>(FuelDiaryVo.class);
        util.exportExcel(response, list, "送料信息数据");
    }

    /**
     * 导出送料日报，按供应商分组导出
     */
    @PreAuthorize("@ss.hasPermi('pound:pound:export')")
    @Log(title = "送料日报", businessType = BusinessType.EXPORT)
    @PostMapping("/exportBySupplier")
    public void exportBySupplier(HttpServletResponse response, FuelPoundParams fuelPoundParams)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        fuelPoundParams.setFactoryId(sysUser.getBizId());
        List<FuelDiaryVo> list = fuelPoundService.selectFuelPoundBySupplierId(fuelPoundParams);
        ExcelUtil<FuelDiaryVo> util = new ExcelUtil<FuelDiaryVo>(FuelDiaryVo.class);
        util.exportExcel(response, list, "送料信息数据");
    }
}
